<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <style type="text/css">
        p {
            margin-bottom: 0.5rem;
        }
        ::-webkit-input-placeholder { /* WebKit browsers */
            color:    #eaeaea;
        }
        :-moz-placeholder { /* Mozilla Firefox 4 to 18 */
            color:    #eaeaea;
        }
        ::-moz-placeholder { /* Mozilla Firefox 19+ */
            color:    #eaeaea;
        }
        :-ms-input-placeholder { /* Internet Explorer 10+ */
            color:    #eaeaea;
        }
        .login-bg2{
            background: linear-gradient(to right,#1c1b18 0,#5b470e 100%);
            background-repeat: no-repeat;
            background-size: 100% 100%;
            -moz-background-size: 100% 100%;
        }
    </style>
</head>
<body class="login-bg2">
  <header class="aui-bar aui-bar-nav" id="aui-header" style="background-color:rgba(0,0,0,0) !important">
      <a class="aui-btn aui-pull-left" tapmode onclick="closeWin()">
          <span class="aui-iconfont aui-icon-left"></span>
      </a>
      <div id="title" class="aui-title">找回密码</div>
  </header>


  <div class="myui-from">
      <ul class="myui-from-list">
          <li class="myui-from-list-item">
              <div class="myui-code">
                  <input id="email" type="text"  placeholder="输入账号绑定的邮箱" class="myui-from-list-item-input">
              </div>
          </li>
          <li class="myui-from-list-item">
              <input id="password" type="text" placeholder="请输入新密码" class="myui-from-list-item-input">
          </li>
          <li class="myui-from-list-item">
              <input id="yzm" type="text" placeholder="请输入验证码" style="width: 150px;float: left" class="myui-from-list-item-input">
              <span id="getcode2">
                  <input type="button" id="getcode" style="width: 41%;height:10%;float: left;background-color: #ff5e3e;padding: 10px;font-size: 18px" onclick="getCode()" value="获取验证码">
              </span>
          </li>
          <li class="myui-from-list-item">
              <button id="btn2" type="button" name="button" class="myui-from-list-item-button" onclick="toReg()">找回密码</button>
          </li>
      </ul>
  </div>

</body>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript">
    var api_url = localStorage.getItem('api_url');
    var onoff = true;
  //  var code_data = '';
    apiready = function () {
      api.parseTapmode();
      var header = $api.byId('aui-header');
      $api.fixStatusBar(header);
      var headerPos = $api.offset(header);
      var body_h = $api.offset($api.dom('body')).h;

    }
    function closeWin(){
        api.closeWin({
        });
    }



    //huoqu
    function getCode() {
        var email = $api.val($api.byId('email'));//邮箱
        if(email == ''){
            api.toast({
                msg: '(邮箱不能为空！)',
                duration: 1000
            });
            return;
        }
        api.ajax({
            url: api_url+"/login/login/sendemailcode.html",
            method: 'get',
            data: {
                values: {
                    email:email
                }
            }
        },function(ret, err){
            if (ret) {
                if (ret.code == 0) {
                    api.toast({
                        msg: ret.msg,
                        duration: 1200
                    });
                }else {
                    var obj_code=$api.byId('getcode')
                    api.toast({
                        msg: '已发送',
                        duration: 1200
                    });
                    setCode(obj_code, 60);
                }
            } else {
                api.toast({
                    msg: '网络异常',
                    duration: 1200
                });

            }
        });
    }

    /**
     * 发送验证码倒计时
     * @param obj_code 对象元素
     * @param countdown 倒计时秒数
     */
    function setCode(obj_code, countdown) {
        if (countdown == 0) {
            //obj_code.attr('disabled', false);
            //obj_code.value("获取验证码");
            $api.byId('getcode2').innerHTML="<input type='button' id='getcode' style='width: 41%;height:10%;float: left;background-color: #ff5e3e;padding: 10px;font-size: 18px' onclick='getCode()' value='获取验证码'>";
            sessionStorage.removeItem("countdown");
            return;
        } else {
            //obj_code.attr('disabled', true);
            //$api.val(obj_code,"重新发送(" + countdown + ")");
            //obj_code.value("重新发送(" + countdown + ")");
            var aaa="重新发送(" + countdown + ")";
            $api.byId('getcode2').innerHTML="<input type='button' id='getcode' disabled='disabled' style='width: 41%;height:10%;float: left;background-color: #ff5e3e;padding: 10px;font-size: 18px' onclick='getCode()' value='"+aaa+"'>";
            countdown--;
        }
        sessionStorage.setItem("countdown", countdown);
        setTimeout(function () {
            setCode(obj_code, countdown);
        },1000);
    }


    function toReg(){
      var password = $api.val($api.byId('password'));
     var yzm = $api.val($api.byId('yzm'));
     var email = $api.val($api.byId('email'));

      if(yzm == ''){
        api.alert({
            title: '调皮~',
            msg: '请输入验证码',
        });
        return;
      }
      if(password == ''){
        api.alert({
            title: '调皮~',
            msg: '请输入密码',
        });
        return;
      }
      api.ajax({
          url: api_url+'/login/login/repasshmyx.html',
          method: 'get',
          data: {
              values: {
                  password:password,
                  email:email,
                  yzm: yzm,
                  mike_key:localStorage.getItem('mike_key')
              }
          }
      },function(ret, err){
          if (ret) {
              if (ret.code == 0) {
                api.alert({
                    title: '修改失败！',
                    msg: ret.msg,
                });
              }else {
                localStorage.setItem('password',password);
                api.alert({
                    title: '修改成功',
                    msg: '请重新登录！',
                });
                api.sendEvent({
                  name: 'outLogin',
                  extra: {
                  }
                });

                api.closeWin();
              }
          } else {
            api.alert({
                title: '糟糕~',
                msg: '请联系客服修改！',
            });
          }
      });
    }


    function openLogin(name,password){
        var delay = 0;
        if(api.systemType != 'ios'){
            delay = 300;
        }
        api.openWin({
            name: 'login',
            url: './login.html',
            pageParam:{name:name,password:password},
        });
    }

    //获取验证码
  /*  function getCode(){
      var yzcode = $api.val($api.byId('yzcode'));

      var username = $api.val($api.byId('username'));
      if (!onoff) {
        return;
      }
      onoff = false;

      if(username == ''){
        api.alert({
            title: '调皮~',
            msg: '请输入手机号码',
        });
        onoff = true;
        return;
      }
      if(username.length != 11){
        api.alert({
            title: '调皮~',
            msg: '请输入11位手机号码',
        });
        onoff = true;
        return;
      }
      code_data = RndNum(6);
      var content = escape('#code#='+code_data);
      //alert(content);
      api.ajax({
          url: 'http://124.222.162.204:1002/login/login/yzcode.html',
          method: 'get',
          data: {
              values: {
                  username: username,
                  key: code_data
              }
          }
      },function(ret, err){
        if (ret.code==0) {
          onoff = true;
          api.alert({
              title: '提示',
              msg: ret.msg,
          });
          return;
        }else {
          onoff = true;
          getApicode(username,content);
        }
      });

    }
    //生成验证码
    function RndNum(n){
      var rnd="";
      for(var i=0;i<n;i++)
          rnd+=Math.floor(Math.random()*10);
      return rnd;
    }

    function getApicode(username,content) {
      var btn1 = $api.byId('btn1');
      api.ajax({
          url: 'http://v.juhe.cn/sms/send?mobile='+username+'&tpl_id=92936&tpl_value='+content+'&key=bd5e9cb24c1e095730b6c9f9ca181410 ',
          method: 'get'
      },function(ret, err){
              api.toast({
                  msg: '发送成功',
                  duration: 1000,
                  location: 'middle'
              });
              var nuw = 120;
              var timer = setInterval(function(){
                nuw --;

                if (nuw < 1) {
                  btn1.innerHTML = '获取';
                  clearInterval(timer);
                  onoff = true;
                }else {
                  btn1.innerHTML = nuw+'s';
                }


              },1000)
      });
    }

*/


    function openWin(name){
          var delay = 0;
          if(api.systemType != 'ios'){
              delay = 300;
          }
          api.openWin({
              name: ''+name+'',
              url: ''+name+'.html',
              bounces:false,
              delay: delay,
              slidBackEnabled:true,
              vScrollBarEnabled:false
          });
      }
</script>
</html>
